/**
 * 
 */
package com.haisen.lee.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;

import com.haisen.lee.exception.ParameterException;

/**
 * @author Haisen Lee
 * 
 */
public class SystemParameter {

	private static Properties systemParameterProp = new Properties();
	private static final String systemParameterFileName = "SystemParameter.properties";
	private static Map<String, String> systemParameters = new HashMap<String, String>();
	private static List<DOMParserType> domParserTypeList = new ArrayList<DOMParserType>();

	/**
	 * 
	 */
	private SystemParameter() {
		super();
	}

	static {
		try {
			systemParameterProp.load(SystemParameter.class.getClassLoader()
					.getResourceAsStream(
							SystemParameter.systemParameterFileName));
			for (DOMParserType item : DOMParserType.values()) {
				domParserTypeList.add(item);
			}
			Iterator<Map.Entry<Object, Object>> systemParameterIterator = systemParameterProp
					.entrySet().iterator();

			for (; systemParameterIterator.hasNext();) {
				Entry<Object, Object> temp = systemParameterIterator.next();
				if (temp.getKey() != null && temp.getValue() != null
						&& temp.getKey().toString() != null
						&& temp.getValue().toString() != null) {
					systemParameters.put(temp.getKey().toString(), temp
							.getValue().toString());
				} else {
					throw new ParameterException(
							"Parameter exception getting file "
									+ SystemParameter.systemParameterFileName
									+ " parameters");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParameterException pe) {
			pe.printStackTrace();
		}
	}

	public static Map<String, String> getAllParameters() {
		return SystemParameter.systemParameters;
	}

	public static String getValue(String key) {
		if (SystemParameter.systemParameters.containsKey(key)) {
			return SystemParameter.systemParameters.get(key);
		} else {
			return null;
		}
	}

}
